Skip to content

Conversation

Copy link

Copilot AI commented Jan 4, 2026

Implements Casbin authorization middleware for Qwik framework with support for HTTP Basic Authentication, custom auth methods, and extensible authorizer interface.

Implementation

  • Core middleware (src/authz.ts): Qwik RequestHandler that enforces Casbin policies based on user, path, and HTTP method
  • BasicAuthorizer: Extracts username from HTTP Basic Auth header or event.sharedMap for custom auth flows
  • Authorizer interface: Allows custom authorization logic while maintaining Casbin integration
  • TypeScript types: Full type definitions for @builder.io/qwik-city integration

Usage

import { newEnforcer } from 'casbin';
import { authz } from 'qwik-authz';

const enforcer = await newEnforcer('model.conf', 'policy.csv');

// Basic usage
export const onRequest = authz({ newEnforcer: enforcer });

// Custom auth (JWT/OAuth)
export const onRequest = async (event) => {
  event.sharedMap.set('username', await verifyToken(event));
};
export const onGet = authz({ newEnforcer: enforcer });

// Custom authorizer
class MyAuthorizer implements Authorizer {
  async checkPermission(): Promise<boolean> {
    // Custom logic + Casbin enforcement
  }
}
export const onRequest = authz({ 
  newEnforcer: enforcer, 
  authorizer: MyAuthorizer 
});

Testing & CI

  • 17 unit tests covering authentication modes, authorization flows, and error cases
  • GitHub Actions workflow: lint → test + coverage → semantic-release
  • Node.js 24 LTS, triggers on push/PR to master
  • Apache 2.0 headers (2026) on all source files
Original prompt

This section details on the original issue you should resolve

<issue_title>[feature] add the code for qwik-authz</issue_title>
<issue_description>need to develop the Qwik: https://github.com/QwikDev/qwik middleware for casbin in this repo

needs to have code (apache header year is 2026) and unit tests

need to have CI (use semantic-release and below trigger)

To:

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

CI only needs to run against Node.js 24 LTS

need to have a README (with badges)

about how to implement, refer to a similar repo: https://github.com/node-casbin/typeorm-adapter</issue_description>

Comments on the Issue (you are @copilot in this section)

@hsluoyz @nodece @Shivansh-yadav13

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@hsluoyz hsluoyz requested a review from nodece January 4, 2026 16:42
@hsluoyz
Copy link
Member

hsluoyz commented Jan 4, 2026

@nodece @Shivansh-yadav13 please review

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hsluoyz hsluoyz marked this pull request as ready for review January 4, 2026 16:48
Copilot AI changed the title [WIP] Add Qwik middleware for casbin implementation Implement qwik-authz middleware for Casbin authorization Jan 4, 2026
Copilot AI requested a review from hsluoyz January 4, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] add the code for qwik-authz

3 participants